package com.mobileagri.backoffice.controller;

import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.mobileagri.backoffice.model.Utilisateur;
import com.mobileagri.backoffice.service.UtilisateurService;
import com.mobileagri.backoffice.util.ExtJSReturn;

/**
 * Controller - Spring
 * 
 * 
 * @author LOUVET Romain
 */
@Controller
public class UtilisateurController {

	private UtilisateurService utilisateurService;

	// @RequestMapping(value = "/contact/view.action")
	// public @ResponseBody
	// Map<String, ? extends Object> view(@RequestParam int start,
	// @RequestParam int limit) throws Exception {
	//
	// try {
	//
	// List<Contact> contacts = contactService
	// .getContactList(start, limit);
	//
	// int total = contactService.getTotalContacts();
	//
	// return ExtJSReturn.mapOK(contacts, total);
	//
	// } catch (Exception e) {
	//
	// return ExtJSReturn
	// .mapError("Error retrieving Contacts from database.");
	// }
	// }

	@RequestMapping(value = "utilisateur/view2", method = RequestMethod.GET)
	public @ResponseBody
	Map<String, ? extends Object> view2(@RequestParam int start,
			@RequestParam int limit) throws Exception {

		System.out.println("utilisateur/view2:start:" + start + ", limit:"
				+ limit);

		try {

			List<Utilisateur> messages = utilisateurService.getUserList(start,
					limit);

			// contactService.getContactList(start, limit)
			//

			int total = utilisateurService.getTotalUser();

			return ExtJSReturn.mapOK(messages, total);

		} catch (Exception e) {

			return ExtJSReturn
					.mapError("Error retrieving Message from database."
							+ e.getMessage());
		}
	}

	// @RequestMapping(value = "/contact/create.action")
	// public @ResponseBody
	// Map<String, ? extends Object> create(@RequestBody Contact data)
	// throws Exception {
	//
	// try {
	//
	// List<Contact> contacts = contactService.create(data);
	//
	// return ExtJSReturn.mapOK(contacts);
	//
	// } catch (Exception e) {
	//
	// return ExtJSReturn.mapError("Error trying to create contact.");
	// }
	// }
	//
	// @RequestMapping(value = "/contact/update.action")
	// public @ResponseBody
	// Map<String, ? extends Object> update(@RequestBody ContactWrapper data)
	// throws Exception {
	// try {
	//
	// List<Contact> contacts = contactService.update(data.getData());
	//
	// return ExtJSReturn.mapOK(contacts);
	//
	// } catch (Exception e) {
	//
	// return ExtJSReturn.mapError("Error trying to update contact.");
	// }
	// }
	//
	// @RequestMapping(value = "/contact/delete.action")
	// public @ResponseBody
	// Map<String, ? extends Object> delete(@RequestBody ContactWrapper data)
	// throws Exception {
	//
	// try {
	//
	// contactService.delete(data.getData());
	//
	// Map<String, Object> modelMap = new HashMap<String, Object>(3);
	// modelMap.put("success", true);
	//
	// return modelMap;
	//
	// } catch (Exception e) {
	//
	// return ExtJSReturn.mapError("Error trying to delete contact.");
	// }
	// }

	@Autowired
	public void setUserService(UtilisateurService utilisateurService) {

		this.utilisateurService = utilisateurService;

	}

}
